<?php echo $this->render($this->includeDir . '/toolbar.php');?>
<?php echo $this->flashMessage();?>

<?php 
	/*===============================================
	 * Filter left
	 *===============================================*/

	$class 	= (empty($arrFilter['keyword']) || $arrFilter['keyword'] == 'none')? 'width-150': 'width-150 bg-green2';
	$keyword 		= $this->formText('keyword',$arrFilter['keyword'],array('class'=>$class));
	
	$categoryOption = array(
							'i.id'			=> $this->translate('- ID field'),
							'i.name'		=> $this->translate('- Name field'),											
							'i.created'		=> $this->translate('- Created field'),
							'u1.user_name'	=> $this->translate('- Created by field'),
							'i.modified'	=> $this->translate('- Modified field'),
							'u2.user_name'	=> $this->translate('- Modified by field'),
							'i.description'	=> $this->translate('- Description field'),
							'i.position'	=> $this->translate('- Position field'),
							'i.email'		=> $this->translate('- Email field'),
							'i.address'		=> $this->translate('- Address field'),
							'i.city'		=> $this->translate('- City field'),
							'i.country'		=> $this->translate('- Country field'),
							'i.website'		=> $this->translate('- Website field'),
						);
						
	$slbFiels	= $this->formSelect('search-field',$arrFilter['searchField'],array('class'=>'width-150'),$categoryOption);
	
	$lnkGo 		= $this->url(array('action'=>'filter','type'=>'search'));
	$btnGo 		= $this->formButton('search',$this->translate("Search"),
								array('onclick'=>"onSubmitForm('appForm','" . $lnkGo . "')",'class'=>'button'));
								
	$lnkClear 	= $this->url(array('action'=>'filter','type'=>'clear'));
	$btnClear 	= $this->formButton('clear',$this->translate("Clear"),
								array('onclick'=>"onSubmitForm('appForm','" . $lnkClear . "')",'class'=>'button'));
								
	$strSearch = '<b>' . $this->translate('Keywords') . ':</b> ' 
				 . $keyword . ' ' . $slbFiels . ' ' . $btnGo . ' ' . $btnClear;		
				 			
	
	/*===============================================
	 * Filter right
	 *===============================================*/	
				 
	$arrParam 	= $this->arrParam;			 	
	$arrFilter 	= $this->arrParam['arrFilter'];
	
	$statusOption 	= array('none'=>'-- ' . $this->translate('Status') . ' --',
						  'active'=>$this->translate('Active'),
						  'inactive'=>$this->translate('Inactive'),
						 );
	$classStatus 	= (empty($arrFilter['area']) || $arrFilter['status'] == 'none')? 'width-150': 'width-150 bg-green2';						 
	$slbStatus 		= $this->formSelect('status',$arrFilter['status'],array('class'=>$classStatus),$statusOption);
	$classCategory 	= (empty($arrFilter['parents']) || $arrFilter['parents'] == 0)? 'width-150': 'width-150 bg-green2';
	array_unshift($this->slbCategory, array('id'=>0,'name'=>' -- ' . $this->translate('Select category'),'level'=>1));
	$slbCategory 	= $this->cmsSelect('catId',$arrFilter['parents'],array('class'=>$classCategory),$this->slbSearchFiels);
	
	$lnkFiter 		= $this->url(array('action'=>'filter','type'=>'filter'));
	$btnFiter 		= $this->formButton('submit-filter',$this->translate("Filter"),
								array('class'=>'button','onclick'=>"onSubmitForm('appForm','" . $lnkFiter . "')"));
	
	$strFilter 		= $slbStatus .' '.$slbCategory.' '. $btnFiter;
					 
?>


<div id="element-box">
            <div class="m">

             	<div class="filter-result">
            		<div style="float: left;">
            			 <?php echo $strSearch;?>
	                </div>
	                <div style="float: right;">
            			<?php echo $strFilter;?>
            		</div>
            		<div class="clr"></div>
            	</div>        
            	   	
                <div class="div-table">
                <table width="100%" border="0" class="adminlist">
                <thead>
                	 <?php 
                	 	$lblName 		= $this->cmsSort($this->translate('Name'), $arrFilter, 'i.name', 'DESC');
                	 	$lblStatus 		= $this->cmsSort($this->translate('Status'), $arrFilter, 'i.status', 'DESC');
                	 	$lblCreated 	= $this->cmsSort($this->translate('Created'), $arrFilter, 'i.created', 'DESC');
                	 	$lblCreatedBy	= $this->cmsSort($this->translate('Created by'), $arrFilter, 'i.created_by', 'DESC');
						$lblOrdering 	= $this->cmsSort($this->translate('Ordering'), $arrFilter, 'i.ordering', 'DESC');
                	 	$lblCategory 	= $this->cmsSort($this->translate('Category'), $arrFilter, 'i.category_id', 'DESC');
                	 	$lblControl		= $this->translate('Control');
                	 	$lblID 			= $this->cmsSort($this->translate('ID'), $arrFilter, 'i.id', 'DESC');
 
                	 	require 'includes/row-thead.php';
                	 ?>
                	</thead> 
                	 <?php 
                	 	if(count($this->Item)>0){
                	 		$i = 1;
                	 		
	                	 		foreach ($this->Item as $key=> $val){
	                	 			
		                	 		$cid 			= $this->formCheckbox('cid[]',$val['id']);
		                	 		$cssTR = 'odd';
		                 			if($i%2==0) $cssTR = 'even';
		                 			
		                 			if($val['level'] == 1){
										$name 	= '<div> + ' . Zendvn_Filter_Filter::filterContent($val['name'],'filter') . '</div>';
									}else{
										$x 		= 40 * ($val['level']-1);
										$css 	= 'padding-left: ' . $x . 'px;';
										$name 	= '<div style="' . $css . '">- ' . Zendvn_Filter_Filter::filterContent($val['name'],'filter') . '</div>';
									}
		                	 			
									// status
									$attribs = array('icon'=>'inactive.png','iconDir' => "images/small-icons/");
									if($val['status'] == 'active')$attribs['icon'] = 'active.png';
									$lnkStatus  = $this->url(array('action'=>'status','id'=> $val['id'],'s'=>$val['status']));
									$status 	= $this->cmsIcon('Status',$lnkStatus,$attribs);
									
									//category
									$category		= Zendvn_Filter_Filter::filterContent($val['cat_id'],'filter');
									
									//order
		                 			$orderingName 	= 'ordering[' . $val['id'] . ']';
									$ordering 		= $this->formText($orderingName,$val['ordering'],array('class'=>'width-50 bg-green center'));
									
									//create
									$created 	= $val['created'];
									
									//createby
									$createdby 		= Zendvn_Filter_Filter::filterContent($val['created_by'],'filter');
									
									//control info
									$lnkInfo  	= $this->url(array('action'=>'info','id'=> $val['id']));
									$iconInfo 	= $this->cmsIcon('View Info',$lnkInfo,array('icon'=>'icon-info.png'));
									
									//control edit
									$lnkEdit  	= $this->url(array('action'=>'edit','id'=> $val['id']));
									$iconEdit 	= $this->cmsIcon('Edit item',$lnkEdit,array('icon'=>'icon-edit.png'));
									
									//control delete
									$lnkDel  = $this->url(array('action'=>'delete','id'=> $val['id']));
									$options = array('type'=>'submit','name'=>'appForm',
														 'notice'=>$this->translate('Are you sure you want to delete this item?'));
									$iconDel = $this->cmsIcon('Delete item',$lnkDel,array('icon'=>'icon-delete.png'),$options);
									
									$control = '---';
									$control 	= $iconInfo . ' ' . $iconEdit . ' ' . $iconDel;
									
									$id = $val['id'];
									
		                	 		require 'includes/row-tbody.php';
		                	 		$i++;	
	                	 		}
                	 		}else{ 
                	 			//neu khong co item 
                	 			echo $this->render('empty.php');
                	 		}	
                	 ?> 
                 </thead>
                  <tfoot>
                      <tr>
                        <td colspan="15">
                        	<?php echo $this->paginationControl($this->panigator,'Sliding','paning.php',array('arrParam'=>$arrParam));?>
                        </td>
                      </tr>
                  </tfoot>
                   </table>

                </div>
            </div>
         </div>